home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 020a / dvpt20.zip / VPDDTEST.C < prev    next >
C/C++ Source or Header  |  1991-12-12  |  4KB  |  188 lines

  1. /****************************************************************/
  2. /*                                                              */
  3. /*             Digitized Voice Programmer's Toolkit             */
  4. /*             ------------------------------------             */
  5. /*                                                              */
  6. /*             Playback example using Device Driver             */
  7. /*                                                              */
  8. /*            Copyright (c) 1991, Farpoint Software             */
  9. /*                                                              */
  10. /****************************************************************/
  11.  
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <malloc.h>
  15. #include <fcntl.h>
  16. #include <io.h>
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include <bios.h>
  20. #include <string.h>
  21.  
  22. char logo[] = "Digitized Voice Playback Device Driver Test Program\r\n"
  23.  "Copyright(c) 1991, Farpoint Software\r\n";
  24.  
  25. unsigned char devicename[] = "FSVPDD$$";
  26. char filename[128];
  27. char huge *buffer;
  28. int handle;
  29. long file_size;
  30.  
  31. /*-------------------------------------------------------------------*/
  32.  
  33. /* This a time delay of about one second. */
  34.  
  35. void one_second(void)
  36.  
  37. {
  38. _asm
  39.     {
  40.             sti
  41.             mov     ax,40h
  42.             mov     es,ax
  43.             mov     bx,6Ch
  44.             mov     cx,18
  45.     osd01:  mov     ax,es:[bx]
  46.     osd02:  cmp     ax,es:[bx]
  47.             je      osd02
  48.             loop    osd01
  49.     }
  50. }
  51.  
  52. /*-------------------------------------------------------------------*/
  53.  
  54. /* program entry point */
  55.  
  56. void main(argc, argv)
  57. int argc;
  58. char **argv;
  59.  
  60. {
  61. unsigned short sizelo, sizehi;   /* used to partition file load process */
  62. unsigned short i;
  63. char huge *loadptr;           /* 32 bit pointer used during loading */
  64. long byte_count;              /* count of bytes played */
  65. int device_handle;            /* handle obtained from opening device driver */
  66.  
  67. /* display the logo */
  68.  
  69. puts(logo);
  70.  
  71. /* check for one argument on command line */
  72.  
  73. if ( argc < 2 )
  74.     {
  75.     puts("Include file name on command line.");
  76.     exit(1);
  77.     }
  78.  
  79. argv++;
  80. strcpy(filename, *argv);
  81.  
  82. /* open the file */
  83.  
  84. handle = open(filename, O_BINARY|O_RDONLY);
  85. if ( handle == -1 )
  86.     {
  87.     puts("Error opening file.");
  88.     exit(1);
  89.     }
  90.  
  91. /* get the file length */
  92.  
  93. file_size = filelength(handle);
  94. if ( file_size == 0L )
  95.     {
  96.     close(handle);
  97.     puts("File has zero length.");
  98.     exit(1);
  99.     }
  100.  
  101. /* allocate memory for the buffer plus 4 bytes for length dword */
  102.  
  103. buffer = (char huge *)halloc(file_size + 4L, 1);
  104. if ( buffer == NULL )
  105.     {
  106.     close(handle);
  107.     puts("Unable to allocate buffer memory.");
  108.     exit(1);
  109.     }
  110.  
  111. /* read the file into the buffer */
  112.  
  113. sizelo = (unsigned short)(file_size & 0x7FFFL);
  114. sizehi = (unsigned short)(file_size >> 15);
  115. loadptr = &buffer[4L];                      /* leave room for length dword */
  116. for ( i = 0 ; i < sizehi ; i++)
  117.     {
  118.     if ( 32768U != (unsigned)read(handle, loadptr, 32768U) )
  119.         {
  120.         close(handle);
  121.         hfree(buffer);
  122.         puts("File read error.");
  123.         exit(1);
  124.         }
  125.     loadptr += 32768;
  126.     }
  127. if ( sizelo )
  128.     {
  129.     if ( sizelo != (unsigned)read(handle, loadptr, sizelo) )
  130.         {
  131.         close(handle);
  132.         hfree(buffer);
  133.         puts("File read error.");
  134.         exit(1);
  135.         }
  136.     }
  137.  
  138. /* close the file */
  139.  
  140. close(handle);
  141.  
  142. /* copy the file size into the first 4 bytes ofthe buffer */
  143.  
  144. memcpy(buffer, &file_size, sizeof(long));
  145.  
  146. /* wait one second so that the key release won't abort playback */
  147.  
  148. one_second();
  149.  
  150. /* open the device */
  151.  
  152. device_handle = open(devicename, O_BINARY|O_RDWR);
  153. if ( device_handle == -1 )
  154.     {
  155.     printf("Error - Unable to open device %s\n", devicename);
  156.     exit(1);
  157.     }
  158.  
  159. /* user informational messages */
  160.  
  161. puts("Press any key to stop.");
  162. puts("Starting...");
  163.  
  164. /* perform the playback */
  165.  
  166. write(device_handle, buffer, 1);           /* always pass "1" as the length */
  167.  
  168. /* get the actual number of bytes played */
  169.  
  170. read(device_handle, &byte_count, 1);       /* always pass "1" as the length */
  171.  
  172. /* tell user that it's done */
  173.  
  174. puts("Done.");
  175.  
  176. /* close the device */
  177.  
  178. close(device_handle);
  179.  
  180. /* show the number of bytes played */
  181.  
  182. printf("%ld bytes played.\n", byte_count);
  183.  
  184. /* free the allocated memory */
  185.  
  186. hfree(buffer);
  187. }
  188.